/*
 * Copyright (C) 2011 TopCoder Inc., All Rights Reserved.
 */
package gov.nasa.pds.services.impl;

import org.springframework.beans.factory.InitializingBean;

import com.topcoder.util.log.Log;

import gov.nasa.pds.services.AdHocQueryTranslator;
import gov.nasa.pds.services.DataSetProcessingException;

/**
 * <p>
 * This class translates the provided user query into a more structure string that the module can use.
 * </p>
 *
 * <p>
 * <b>Thread Safety:</b> The implementations are effectively thread-safe.
 * </p>
 *
 * @author argolite, TCSASSEMBLER
 * @version 1.0
 */
public class AdHocQueryTranslatorImpl implements AdHocQueryTranslator, InitializingBean {
    /**
     * Represents the class name.
     */
    private static final String CLASS_NAME = AdHocQueryTranslatorImpl.class.getName();

    /**
     * Represents the log instance used for logging.
     */
    private Log logger;

    /**
     * The default do nothing constructor.
     */
    public AdHocQueryTranslatorImpl() {
    }

    /**
     * Sets the log instance used for logging.
     * @param logger the log instance used for logging
     */
    public void setLogger(Log logger) {
        this.logger = logger;
    }

    /**
     * Checks whether this class was initialized by Spring properly.
     *
     * @throws DataSetProcessingException if logger is null
     */
    @Override
    public void afterPropertiesSet() throws DataSetProcessingException {
        Helper.checkNotNull("logger", logger);
    }

    /**
     * Translates the adHoc query into something more structured.
     *
     * @param adHocQuery the adHoc query
     * @return the more structured version of the query
     * @throws DataSetProcessingException if there is an error while getting the data
     */
    public String translateQuery(String adHocQuery) throws DataSetProcessingException {
        // The default implementation will just return the query which is expected to be a well-formed SQL
        // query
        String name = CLASS_NAME + ".createTableStructure(Table table)";
        Helper.logMethodEntryAndInputParameters(logger, name, new String[] {"adHocQuery"},
                new Object[] {adHocQuery});
        Helper.logMethodExitAndOutputParameters(logger, name, true, adHocQuery);
        return adHocQuery;
    }
}